package org.jaaksi.kottlindemo.dao

import android.content.Context
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import org.jaaksi.greendao.gen.DaoMaster
import org.jaaksi.greendao.gen.DaoSession
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
class DatabaseModule {

    @Singleton
    @Provides
    fun providerDaoSession(@ApplicationContext context: Context): DaoSession {
        val helper = DaoMaster.DevOpenHelper(context, "demo.db")
        val db = helper.writableDatabase
        val daoMaster = DaoMaster(db)
        return daoMaster.newSession()
    }
}